package com.example.config;

import com.example.filter.WebVisitFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;

/**
 * TODO
 *
 * @Author gaokaikai
 * @CreateDate 2023/3/14 17:31
 * @Version 1.0
 */
@Configuration
public class WebVisitFilterConfig {
    @SuppressWarnings({"rawtypes", "unchecked"})
    @Bean
    public FilterRegistrationBean webVisitFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(createWebVisitFilter());
        registration.setName("webVisitFilter");
        registration.setOrder(Integer.MIN_VALUE + 4); // 越小优先级越高
        System.out.println("filter0================================="+Integer.MIN_VALUE + 4);
        return registration;
    }

    @Bean
    public WebVisitFilter createWebVisitFilter() {
        return new WebVisitFilter(); // now this is a Spring bean
    }
}
